# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgname=('mpfr' 'mpfr-devel')
_pkgver=4.0.1
_patchlevel=
pkgver=${_pkgver}
if [ -n "${_patchlevel}" ]; then
  pkgver+=.${_patchlevel}
fi
#pkgver=${_pkgver}
pkgrel=1
pkgdesc="Multiple-precision floating-point library"
arch=('i686' 'x86_64')
url="http://www.mpfr.org/"
license=('LGPL')
depends=('gmp>=5.0')
makedepends=('gmp-devel>=5.0')
source=(http://www.mpfr.org/mpfr-current/mpfr-${_pkgver}.tar.xz{,.asc}
        mpfr-3.1.6-p1.patch
        mpfr-4.0.0-msys2.patch
        mpfr-4.0.0-add-ax_thread_m4.patch)
validpgpkeys=('07F3DBBECC1A39605078094D980C197698C3739D')
sha256sums=('67874a60826303ee2fb6affc6dc0ddd3e749e9bfcb4c8655e3953d0458a6e16e'
            'SKIP'
            '5d37e47d9d206b1b306dfd590b3019c3f2651013403bb5cb290d1173ed080b28'
            '54d418ee7afc1f3e74f4db08e8205eec48751f4d8da96f536d4c7e706a5d67c0'
            '20e1297e222e8736ff06d7ea671abf528437f8ccf4648bb1838d2ff620c0842d')

prepare() {
  cd "${srcdir}/${pkgname}-${_pkgver}"
  #  patch -p1 -i ${srcdir}/mpfr-3.1.6-p1.patch
  patch -p1 -i ${srcdir}/mpfr-4.0.0-msys2.patch
  patch -p1 -i ${srcdir}/mpfr-4.0.0-add-ax_thread_m4.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${_pkgver}"
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --disable-static
  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/${pkgname}-${_pkgver}"
  make check
}

package_mpfr() {
  groups=('libraries')
  install=mpfr.install

  mkdir -p ${pkgdir}/usr

  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_mpfr-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("mpfr=${pkgver}" 'gmp-devel')
  pkgdesc="MPFR headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
